//
//  LoginViewController.m
//  HallOrder
//
//  Created by 蒋 浩锋 on 12-10-19.
//  Copyright (c) 2012年 蒋 浩锋. All rights reserved.
//

#import "LoginViewController.h"
#import "CommonObject/ServerNetworkCenter.h"
#import "CommonObject/ClientNetworkCenter.h"
#import "Plugin/MBProgressHUD/MBProgressHUD.h"
#import "CommonObject/DataCenter.h"
#import "CommonObject/SocketDataHandle.h"
#import "RoomStatesObject.h"

@interface LoginViewController ()<SocketDataHandleDelegate,UITextFieldDelegate>
{
    NSString *uuid;
    NSString *userName;
    NSString *passwdrd;
    UITextField *currentTextField;
}

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [SocketDataHandle sharedInstance].delegate = self;
	// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    currentTextField = textField;
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.tag == 100)
    {
        userName = textField.text;
    }else
    {
        passwdrd = textField.text;
    }
}
- (IBAction)btnLoginAction:(id)sender
{
    [currentTextField resignFirstResponder];
    NSLog(@"username :%@,password :%@",userName,passwdrd);
    [[ServerNetworkCenter sharedInstance] sentMsg:rtHallBound:[DataCenter sharedInstance].UDID,@"0",userName,passwdrd, nil];
}
-(void)socketDataHandleDidHallBound:(BOOL)isBound errorMsg:(NSString *)errorMsg
{
    if (isBound)
    {
        [self performSegueWithIdentifier:@"showRoonStatesVC" sender:self];
    }else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:errorMsg delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
        alert.tag = 0;
        [alert show];
    }
}
@end
